import { customRef } from "vue";

export default function useDebounceRef<T>(value:T,delay=200){
    let timeout:number;
    return customRef((track,trigger)=>{
        return{
            get(){
                track();
                return value;
            },
            set(newValue:T){
                clearTimeout(timeout);
                value=newValue;
                timeout=setTimeout(()=>{
                    trigger();
                },delay)
            }
        }
    })
}